from Foo.capability_json import getDriver
from Foo.login import Login
from Foo.pageSwitch import PageSwitch
from util.baseView import BaseView
from selenium.webdriver.common.by import By
from appium.webdriver.common.touch_action import TouchAction
import logging
import logging.config

import time
class Person(BaseView):
    CON_LOG = '../docs/log.conf'
    logging.config.fileConfig(CON_LOG)
    def __init__(self,driver):
        BaseView.__init__(self,driver)
        self.image_icon = (By.ID, 'com.sykean.biometrics:id/imageView_face_icon')
        self.edit = (By.ID,'com.sykean.biometrics:id/modify')  #人员编辑按钮
        self.iris_capture = (By.ID,'com.sykean.biometrics:id/btn_iris_capture')  # 虹膜采集
        self.face_capture = (By.ID,'com.sykean.biometrics:id/btn_face_capture')
        self.dialog_ok =(By.ID,'com.sykean.biometrics:id/btn_dialog_ok') # 确认是否重新采集虹膜
        self.dialog_cancel = (By.ID,'com.sykean.biometrics:id/btn_dialog_cancel') # 确认是否取消本次操作
        self.back = (By.ID, 'com.sykean.biometrics:id/btn_back')
    def test_edit_person(self):
        el = self.find_element(*self.image_icon)
        # 长按
        TouchAction(self.driver).long_press(el).perform()
        time.sleep(2)
        self.click_element(*self.edit)
    def test_iris_capture(self):

        try:
            el = self.find_element(*self.dialog_cancel)
            if el:
                self.click_element(*self.dialog_cancel)
        except:
            print('未找到确认取消按钮')
        logging.info('点击虹膜采集按钮')
        self.click_element(*self.iris_capture)
        self.click_element(*self.dialog_ok)
        time.sleep(5)
        self.click_element(*self.back)
    def test_face_capture(self):

        try:
            el = self.find_element(*self.dialog_cancel)
            if el:
                self.click_element(*self.dialog_cancel)
        except:
            print('未找到确认取消按钮')
        logging.info('点击人脸采集按钮')
        self.click_element(*self.face_capture)
        self.click_element(*self.dialog_ok)
        time.sleep(5)
        self.click_element(*self.back)

    

if __name__ == '__main__':
    driver = getDriver()
    Login(driver).login()
    PageSwitch(driver).menuUser()
    Person(driver).test_edit_person()

    while True:
        try:
            Person(driver).test_iris_capture()
            Person(driver).test_face_capture()
        except:
            print('重新采集失败')


